home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9144 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: watnews.watson.ibm.com!ncohen
  2. From: ncohen@watson.ibm.com (Norman H. Cohen)
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: on OO differnces between Ada95 and C++
  5. Date: 28 Feb 1996 20:59:22 GMT
  6. Organization: IBM T.J. Watson Research Center
  7. Distribution: world
  8. Message-ID: <4h2fna$hp6@watnews1.watson.ibm.com>
  9. References: <4gbq7q$g08@qualcomm.com> <4gdidj$10f5@watnews1.watson.ibm.com> <4gveoa$nnd@mulgave.octacon.co.uk>
  10. Reply-To: ncohen@watson.ibm.com
  11. NNTP-Posting-Host: rios8.watson.ibm.com
  12.  
  13. In article <4gveoa$nnd@mulgave.octacon.co.uk>,
  14. Adam.Morris@octacon.co.uk (Adam Morris) writes: 
  15.  
  16. |> In article <4gdidj$10f5@watnews1.watson.ibm.com>,
  17. |>    ncohen@watson.ibm.com (Norman H. Cohen) wrote: 
  18. ...
  19. |>                                                           In C and C++
  20. |> >importing is transitive--if B #includes A and C #includes B, then C has
  21. |> >effectively #included A--while in Ada it is not--if B has a with clause for
  22. |> >A and C has a with clause for B, then A is not visible in C unless C has
  23. |> >its own explicit with clause for A.
  24. |>
  25. |> Only if you do what you shouldn't do...  the .h file should have forward
  26. |> declarations of all classes it uses except in certain cases.  And what are
  27. |> those cases, if A inherits from B then (and only then as far as I know) should
  28. |> you #include B.h in A.h  otherwise you have a declaration saying
  29. |> class B{};
  30.  
  31. Yes, but A.H must include B.H even if A inherits from B as a PRIVATE base
  32. class.  In that case the interface of class B should not in any way be
  33. considered part of the interface of class A, but any file that #includes
  34. A gets gratuitous access to the entities declared in B.H.  This does not
  35. happen in Ada.  The Ada equivalent is
  36.  
  37.    with B_Package;
  38.    package A_Package is
  39.       type A_Type is tagged private;
  40.       ...
  41.    private
  42.       type A_Type is new B_Package.B_Type with ...;
  43.       ...
  44.    end A_Package;
  45.  
  46. A package that has a with clause for A_Package, but not for B_Package,
  47. does not get access to B_Package.
  48.  
  49. The issue arises not only for inheritance, but also for composition.
  50. If A has a private member of class B, A.H must #include B.H.  Again, the
  51. interface of class B is not logically part of the interface for class A,
  52. but you can't #include A.H without also #including B.H.  The Ada
  53. equivalent is
  54.  
  55.    with B_Package;
  56.    package A_Package is
  57.       type A_Type is tagged private;
  58.       ...
  59.    private
  60.       type A_Type is tagged
  61.          record
  62.             ...
  63.             Some_Component: B_Package.B_Type;
  64.             ...
  65.          end record;
  66.       ...
  67.    end A_Package;
  68.  
  69. and once again, a package that has a with clause for A_Package, but not
  70. for B_Package, does not get access to B_Package.
  71.  
  72. --
  73. Norman H. Cohen    ncohen@watson.ibm.com
  74.